<?php

class BottomMenuWidget extends CWidget
{

    public $items;
    public $selectIds;

    private $_html = '';

    public function init()
    {
        $oCategories = new Categories();
        $oPages = new Pages();
        $this->items = $oCategories->getAll(null, true, true, 'page');
	    $oPages->selectByCategoryRowset($this->items);
//        print_r($this->items); exit;
    }

    public function run()
    {
        $this->_tree($this->items);
    }

    protected function _tree($items, $level = 1)
    {
        $this->_html .= '<menu class="bottom-menu">';

        foreach($items as $i => $oCategoryRow)
        {
	        $this->_html .= '<li'. (isset($this->selectIds[$oCategoryRow->id]) ? ' class="selected"' : '') .'>';

            $this->_html .= '<div>'. $oCategoryRow->title .'</div>';

	        if($oCategoryRow->id == 13)
	        {
		        $this->_html .= '<div><a target="_blank" href="http://facebook.com/abobyk">Facebook</a></div>';
		        $this->_html .= '<div><a target="_blank" href="http://vk.com/abobyk">ВКонтакте</a></div>';
		        $this->_html .= '<div><a target="_blank" href="http://plus.google.com/abobyk">Google +</a></div>';
	        }
	        else
	        {
		        if(!empty($oCategoryRow->pages))
		        {
			        foreach($oCategoryRow->pages as $oRow)
			        {
	                    $this->_html .= '<div><a href="'. Yii::app()->controller->createUrl('/pages/default/index', array('id' => $oRow->createUrlId())) .'">'. $oRow->title .'</a></div>';
			        }
		        }
	        }

            $this->_html .= '</li>';
        }

        $this->_html .= '</menu>';

        return $this->_html;
    }

    public function __toString()
    {
        return $this->_html;
    }


}